<html>
<head><meta charset="utf-8"><title>optimizing single-thread overhead · t-compiler/wg-parallel-rustc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/index.html">t-compiler/wg-parallel-rustc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html">optimizing single-thread overhead</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="179363803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179363803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179363803">(Oct 29 2019 at 19:13)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@nnethercote</span> -- it occurred to me that you might be interested in helping to optimize the "single-threaded overhead" of rustc running in parallel mode? </p>
<p>/me tries to nerd-swipe :)</p>



<a name="179377560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179377560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179377560">(Oct 29 2019 at 21:46)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> Possibly, but I've just done 2 solid months of rustc perf work and I kind of need to do some Firefox stuff for a bit :/</p>



<a name="179444340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179444340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179444340">(Oct 30 2019 at 15:33)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@nnethercote</span> heh ok =)</p>



<a name="179481655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179481655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179481655">(Oct 30 2019 at 21:55)</a>:</h4>
<p>How do I build a single-threaded parallel rustc? <code>parallel-compiler = true</code> in <code>config.toml</code> is obvious, but I can't see anything in there about the number of threads</p>



<a name="179481762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179481762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179481762">(Oct 30 2019 at 21:56)</a>:</h4>
<p><code>rustc -Zthreads=N</code> at runtime, perhaps</p>



<a name="179481826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179481826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179481826">(Oct 30 2019 at 21:57)</a>:</h4>
<p>yes, the default is one thread today I believe, but I think it's good practice when benchmarking to always set -Zthreads</p>



<a name="179481838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179481838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179481838">(Oct 30 2019 at 21:57)</a>:</h4>
<p>note that this only affects threads during query-parallelism, not codegen parallelism</p>



<a name="179482053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179482053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179482053">(Oct 30 2019 at 22:00)</a>:</h4>
<p>Yes, default is 1 thread in librustc/session/config.rs, ethanks</p>



<a name="179501411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179501411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179501411">(Oct 31 2019 at 04:48)</a>:</h4>
<p>I did some basic comparisons between serial and parallel with one thread.</p>



<a name="179501424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179501424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179501424">(Oct 31 2019 at 04:49)</a>:</h4>
<p><code>packed-simd</code> has the greatest slowdown for a <code>check-clean</code> build, of about 7%</p>



<a name="179501426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179501426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179501426">(Oct 31 2019 at 04:49)</a>:</h4>
<p>That 7% is dominated by the fact that <code>get_query</code> is more expensive</p>



<a name="179501559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179501559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179501559">(Oct 31 2019 at 04:53)</a>:</h4>
<p>This is mostly due to sharding (which in a serial compiler doesn't really do anything) of the query cache. In particular, when a key is looked up it now gets hashed twice: once in <code>get_shard_by_value</code> to find the shard, and then again to look up the hash table within the shard.</p>



<a name="179501583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179501583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179501583">(Oct 31 2019 at 04:54)</a>:</h4>
<p>There is also some locking overhead, unsurprisingly.</p>



<a name="179501605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179501605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179501605">(Oct 31 2019 at 04:54)</a>:</h4>
<p>I think the duplicate hashing is the biggest source of overhead.</p>



<a name="179501702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179501702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179501702">(Oct 31 2019 at 04:57)</a>:</h4>
<p>It would be nice if we could compute the hash first, then say "get the shard/value using this hash value", but I don't think <code>HashMap</code> allows that.</p>



<a name="179501856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179501856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179501856">(Oct 31 2019 at 05:01)</a>:</h4>
<p>Unless <code>RawEntryBuilderMut</code> can be used for this?</p>



<a name="179502025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179502025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179502025">(Oct 31 2019 at 05:06)</a>:</h4>
<p><code>from_key_hashed_nocheck</code> might do the trick</p>



<a name="179502179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179502179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179502179">(Oct 31 2019 at 05:12)</a>:</h4>
<p>Indeed, I think <code>RawEntryBuilder::from_key_hashed_nocheck</code> does exactly what I want! And <code>Sharded</code> already has <code>get_shard_by_hash</code>. I will try this out tomorrow, see how it goes.</p>



<a name="179516792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179516792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179516792">(Oct 31 2019 at 10:09)</a>:</h4>
<p>Did you look at wall-times? 7% seem low compared to the last time this was benchmarked, unless non-<code>check-clean</code> builds have more overhead. Also which processor do you use?</p>



<a name="179518649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179518649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179518649">(Oct 31 2019 at 10:32)</a>:</h4>
<p><code>try_get</code> hashes the key 3 times now. I tried reducing the 2 hashes to 1 before, but LLVM didn't inline stuff well, so it was a performance regressions. Keys are usually integers too, which means hashing is pretty cheap.</p>



<a name="179598167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179598167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179598167">(Nov 01 2019 at 04:00)</a>:</h4>
<p>Does every query type get its own QueryCache? I count 188 query types</p>



<a name="179598175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179598175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179598175">(Nov 01 2019 at 04:00)</a>:</h4>
<p>And in the parallel compiler they are sharded into 32 pieces,</p>



<a name="179598180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179598180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179598180">(Nov 01 2019 at 04:00)</a>:</h4>
<p>And each QueryCache has two hashmaps.</p>



<a name="179598192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179598192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179598192">(Nov 01 2019 at 04:01)</a>:</h4>
<p>So that's a total of 188 * 32 * 2 = 12,032 hashmaps?</p>



<a name="179599100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179599100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179599100">(Nov 01 2019 at 04:25)</a>:</h4>
<p>Yes</p>



<a name="179663227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179663227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179663227">(Nov 01 2019 at 20:39)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@nnethercote</span> nice :)</p>



<a name="179668654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179668654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179668654">(Nov 01 2019 at 21:51)</a>:</h4>
<p>@nikomatsakis: <a href="https://github.com/rust-lang/rust/pull/66013" target="_blank" title="https://github.com/rust-lang/rust/pull/66013">https://github.com/rust-lang/rust/pull/66013</a> is the PR that eliminates the repeated hashing</p>



<a name="179668773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179668773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179668773">(Nov 01 2019 at 21:52)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/66012" target="_blank" title="https://github.com/rust-lang/rust/pull/66012">https://github.com/rust-lang/rust/pull/66012</a> is an interesting one -- I de-querified <code>trivial_dropck_outlives</code> and it was a perf win for the serial compiler because the cost of querying was actually larger than the cost of re-computing. And the benefit for the parallel compiler could only be higher, because the cost of querying is higher in the parallel compiler</p>



<a name="179668889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179668889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179668889">(Nov 01 2019 at 21:54)</a>:</h4>
<p>FWIW, here are my notes on parallel overhead from yesterday:</p>
<ul>
<li>Overhead is almost all in get_query()<ul>
<li>Lock (<a href="http://atomic.rs" target="_blank" title="http://atomic.rs">atomic.rs</a>, parking_lot) (outweighs the reduction in RefCell use)</li>
<li><a href="http://sharded.rs" target="_blank" title="http://sharded.rs">sharded.rs</a></li>
<li>codegen/regalloc due to more code in get_query</li>
<li>memcpy: QueryJob is bigger (144 bytes), memcpy is needed to initialize it</li>
<li>Note: 188 query kinds, 32 QueryCaches each = 5056, 2 HashMaps each: 12,032 HashMaps!</li>
</ul>
</li>
<li>__tls_get_addr: Rayon calls this a bit</li>
</ul>



<a name="179669887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/179669887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#179669887">(Nov 01 2019 at 22:09)</a>:</h4>
<p>Even in the serial compiler, get_query is hot, and just the instruction counts for entering/exiting it is often 2-3% of all instructions. But it's almost impossible to inline because it has hundreds (thousands?) of call sites, via the query getters</p>



<a name="180084272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180084272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180084272">(Nov 06 2019 at 22:44)</a>:</h4>
<p>The whole query-based design of the compiler is a bit antithetical to parallelization -- everything centres around a giant chunk of shared state</p>



<a name="180084279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180084279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180084279">(Nov 06 2019 at 22:44)</a>:</h4>
<p>the sharding helps, but still</p>



<a name="180084294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180084294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180084294">(Nov 06 2019 at 22:45)</a>:</h4>
<p>I wonder if some per-thread caching might help</p>



<a name="180093197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180093197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180093197">(Nov 07 2019 at 01:07)</a>:</h4>
<p>I definitely think we should explore whether e.g. lockless or eventually consistent hashmaps could be good for us -- a lot of the time, we're fine if we're not quite seeing the most current state for queries</p>



<a name="180093201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180093201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180093201">(Nov 07 2019 at 01:07)</a>:</h4>
<p>(or at least most queries)</p>



<a name="180153547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180153547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hadrien Grasland <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180153547">(Nov 07 2019 at 17:17)</a>:</h4>
<p>Am I correct that this is essentially append-only data ? This is not the worst kind of shared state because at least you don't have the concurrent memory reclamation hell to take care of.</p>



<a name="180153656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180153656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hadrien Grasland <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180153656">(Nov 07 2019 at 17:18)</a>:</h4>
<p>Well, for the hashtable elements at least. Bucket management would be another story...</p>



<a name="180158582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180158582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180158582">(Nov 07 2019 at 18:15)</a>:</h4>
<p>we never delete from the hash tables and so forth so I <em>think</em> we could plausibly be able to come up with something without too much trouble :)</p>



<a name="180185271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180185271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180185271">(Nov 07 2019 at 22:44)</a>:</h4>
<p>One thing that troubles me about the sharding is that it's one-size-fits-all, even though the various query types have very different properties</p>



<a name="180185281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180185281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180185281">(Nov 07 2019 at 22:44)</a>:</h4>
<p>Also, it's not respondent to the number of threads.</p>



<a name="180185307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180185307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180185307">(Nov 07 2019 at 22:45)</a>:</h4>
<p>In contrast, per-thread caching is responsive to the number of threads.</p>



<a name="180577446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180577446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180577446">(Nov 13 2019 at 00:35)</a>:</h4>
<p>I don't think sharding is very problematic. There doesn't seem to be much performance overhead to having too many shards, so we just have to make sure there's enough shards to reduce contention on core counts it make sense to run rustc with.</p>



<a name="180577636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180577636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180577636">(Nov 13 2019 at 00:38)</a>:</h4>
<p>The query-based design is pretty bad for performance overall (expect for incremental performance). I wonder if we can have "thread-local" queries which use thread-local state instead of global state. It would be useful for cheap queries (like symbol names). I would have to think hard about how that would affect recursion detection and incremental things though.</p>



<a name="180742263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing%20single-thread%20overhead/near/180742263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187679-t-compiler/wg-parallel-rustc/topic/optimizing.20single-thread.20overhead.html#180742263">(Nov 14 2019 at 15:41)</a>:</h4>
<p>To clarify something:</p>
<p>When we say that the query-based design is "bad" for parallelism, we are specifically referring to the centralized caches? It seems pretty obviously <em>good</em> for parallelism to me in the sense that the more we can compose the compiler into side-effect-free functions, the better? I find this a bit confusing. It seems like it's more a question of how to arrange the execution than the query-based design <em>itself</em>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>